package net.tngou.crawler.drug.license;



import com.alibaba.fastjson.JSONObject;


import net.tngou.crawler.enums.CfdaEnum;
import net.tngou.crawler.jdbc.DBManager;
import net.tngou.crawler.pojo.License;
import net.tngou.crawler.pojo.POJO;


public class LicenseCrawler extends CN_GOV_CFDA{
	

	public static void init(CfdaEnum cfdaEnum) {
		Long id = getId(cfdaEnum.name());
//		System.err.println(id);
		License license= new License();
		POJO pojo = license.get("type="+cfdaEnum.getIndex()+" AND tid="+id);
		if(pojo!=null) return;
		JSONObject json=getData(cfdaEnum.getIndex(), id);
		if(json==null) return ;
//		System.err.println(json);
		license.setName(json.getString(cfdaEnum.getName_key()));
		license.setNumber(json.getString(cfdaEnum.getNumber_key()));
		license.setContent(json.toJSONString());
		license.setType(cfdaEnum.getIndex());
		license.setTid(id);
		save(license);
		DBManager.closeConnection();
	}
	public static void main(String[] args) {
		CfdaEnum[] values = CfdaEnum.values();
		while (true) {
			for (CfdaEnum cfdaEnum : values) {
				init(cfdaEnum);
			}
			
		}
//		int i=10212;
//		while(true) {
//		System.err.println(i);
//		JSONObject json = CN_GOV_CFDA.getData(22, 2);
//		System.err.println(json);、
//		}
		

	}
}
